﻿namespace Hotel.Web.Models
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.Xml.Serialization;
    using Hotel.Module.Management.Models;
using System.Collections.Generic;

    public class CheckIn
    {
        public void AssignTo(object obj)
        {
            if (obj is Order)
            {
                Order modelOrder = obj as Order;
                modelOrder.Email = ContactInformation.Contacts.EMail;
                modelOrder.Phone = ContactInformation.Contacts.Phone;
                modelOrder.FName = ContactInformation.FName;
                modelOrder.LName = ContactInformation.LName;
                if (RoomType == Hotel.Web.Views.OrderRoom.RoomOrder.Standart)
                {
                    modelOrder.RoomType = ItemTypes.StandartRoom;
                }
                else if (RoomType == Hotel.Web.Views.OrderRoom.RoomOrder.SemiSuit)
                {
                    modelOrder.RoomType = ItemTypes.SemiSuit;
                }
                else if (RoomType == Hotel.Web.Views.OrderRoom.RoomOrder.Suit)
                {
                    modelOrder.RoomType = ItemTypes.Suit;
                }
                else
                {
                    modelOrder.RoomType = ItemTypes.StandartRoom;
                }
                modelOrder.NumberOfRooms = RoomNum;
                modelOrder.NumberOfPeople = NumberOfPeople;
                modelOrder.InDate = InDate.Date;
                modelOrder.OutDate = OutDate.Date;

                return;
            }

            throw new NotSupportedException();
        }

        public static CheckIn FromDomainModel(Order order)
        {
            CheckIn result = new CheckIn();
            result.ContactInformation = new ContactInfo();
            result.ContactInformation.FName = order.FName;
            result.ContactInformation.LName = order.LName;
            result.ContactInformation.Contacts = new Contacts();
            result.ContactInformation.Contacts.EMail = order.Email;
            result.ContactInformation.Contacts.Phone = order.Phone;
            result.InDate = order.InDate;
            result.OutDate = order.OutDate;
            result.NumberOfPeople = order.NumberOfPeople;
            result.RoomNum = order.NumberOfRooms;
            if (order.RoomType == ItemTypes.SemiSuit) {
                result.RoomType = Hotel.Web.Views.OrderRoom.RoomOrder.SemiSuit; 
            }
            else if (order.RoomType == ItemTypes.Suit)
            {
                result.RoomType = Hotel.Web.Views.OrderRoom.RoomOrder.Suit;
            }
            else
            {
                result.RoomType = Hotel.Web.Views.OrderRoom.RoomOrder.Standart;
            }
            result.OrderID = order.ID;
            return result;
        }
        
        
        [XmlIgnore]
        public bool IsRoom { get; set; }

        [Display(ResourceType = typeof(Hotel.Web.Views.CheckInOut.CheckInOutResources), Name = "OrderID")]
        public int OrderID { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "InDate")]
        [DataType(DataType.Date)]
        [XmlAttribute(typeof(DateTime))]
        public DateTime InDate { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "OutDate")]
        [DataType(DataType.Date)]
        [XmlAttribute(typeof(DateTime))]
        public DateTime OutDate { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "ItemType")]
        public string RoomType { get; set; }

        public ContactInfo ContactInformation { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "NumberOfPeople")]
        public int NumberOfPeople { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "RoomNum")]
        public int RoomNum { get; set; }

        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "RoomPackage")]
        public List<int> RoomPackage
        {
            get { return m_RoomPackage; }
            set { m_RoomPackage = value; }
        }

        private List<int> m_RoomPackage = new List<int>();        
    }
}